<?php

namespace app\validate\adm;

use think\Validate;

class CarMileageValidate extends Validate
{
    /**
     * 定义验证规则
     * @var array
     */
    protected $rule = [
        'car_id' => 'require|integer|gt:0',
        'record_date' => 'require|date',
        'start_mileage' => 'integer|egt:0',
        'end_mileage' => 'integer|egt:0|gt:start_mileage',
        'mileage' => 'require|integer|egt:0',
        'start_address' => 'max:200',
        'end_address' => 'max:200',
        'purpose' => 'max:200',
        'driver' => 'max:20',
        'remark' => 'max:500',
    ];

    /**
     * 定义错误信息
     * @var array
     */
    protected $message = [
        'car_id.require' => '车辆ID不能为空',
        'car_id.integer' => '车辆ID必须是整数',
        'car_id.gt' => '车辆ID必须大于0',
        'record_date.require' => '记录日期不能为空',
        'record_date.date' => '记录日期格式不正确',
        'start_mileage.integer' => '起始里程必须是整数',
        'start_mileage.egt' => '起始里程不能为负数',
        'end_mileage.integer' => '结束里程必须是整数',
        'end_mileage.egt' => '结束里程不能为负数',
        'end_mileage.gt' => '结束里程必须大于起始里程',
        'mileage.require' => '行驶里程不能为空',
        'mileage.integer' => '行驶里程必须是整数',
        'mileage.egt' => '行驶里程不能为负数',
        'start_address.max' => '起始地址不能超过200个字符',
        'end_address.max' => '结束地址不能超过200个字符',
        'purpose.max' => '用车事由不能超过200个字符',
        'driver.max' => '驾驶员不能超过20个字符',
        'remark.max' => '备注不能超过500个字符',
    ];

    /**
     * 定义验证场景
     * @var array
     */
    protected $scene = [
        'add' => ['car_id', 'record_date', 'start_mileage', 'end_mileage', 'mileage', 'start_address', 'end_address', 'purpose', 'driver', 'remark'],
        'edit' => ['id', 'car_id', 'record_date', 'start_mileage', 'end_mileage', 'mileage', 'start_address', 'end_address', 'purpose', 'driver', 'remark'],
    ];
}